<template>
  <div class="Delivery">
    <div class="zhi-top">
      <van-icon @click="$router.push({name:'SubmitOrder'})" name="arrow-left" />
      <h3>选择收货地址</h3>
    </div>
    <div class="wu" v-show="isShow" @click.stop>
      <img src="../assets/wudizhi.png" />
      <button @click="$router.push({name:'Xinjian'})">新建地址</button>
    </div>
    <div class="you">
      <div class="box">
        <ul class="deliveryList">
          <li @click="solveaddress(item)" v-for="(item,index) of addresses" :key="item._id">
            <div class="name-tel">
              <span class="span1">{{item.receiver}} {{item.mobile}}</span>
              <br />
              <div class="span2">
                {{item.regions}}
                {{item.address}}
              </div>
            </div>
            <van-icon
              id="bi"
              @click="$router.push({name:'Shanchudizhi',query: {code:addresses[index]}})"
              @click.stop
              name="edit"
            />
          </li>
        </ul>
      </div>
      <button @click="$router.push({name:'Xinjian'})">+ 新建地址</button>
    </div>
  </div>
</template>
<script>
import axios from "axios";
import { mapState, mapMutations, mapAction } from "vuex";
export default {
  data() {
    return {
      isShow: false,
      addresses: []
    };
  },

  created() {
    axios.get("http://192.168.17.95:3000/api/v1/address").then(res => {
      this.addresses = res.data.addresses;
      console.log(this.addresses);
    });
  },
  methods: {
    ...mapMutations("product", ["saveAddress"]),
    solveaddress(item) {
      console.log(item);
      this.saveAddress(item);
      this.$router.push({ name: "SubmitOrder" });
    }
  }
};
</script>
<style scoped>
@import "../css/Delivery.css";
</style>